<template>
  <div class="app-container">
    <!-- 添加或修改就业列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="学生id" prop="studentId">
          <el-input v-model="form.studentId" placeholder="请输入学生id" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="初次报到时间" prop="firstInternshipDate">
          <el-date-picker
            v-model="form.firstInternshipDate"
            clearable
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择初次报到时间"
          />
        </el-form-item>
        <el-form-item label="初次报到单位" prop="firstInternshipCompany">
          <el-input v-model="form.firstInternshipCompany" placeholder="请输入初次报到单位" />
        </el-form-item>
        <el-form-item label="有无变动1" prop="moveOne">
          <el-input v-model="form.moveOne" placeholder="请输入有无变动1" />
        </el-form-item>
        <el-form-item label="有无变动2" prop="moveTwo">
          <el-input v-model="form.moveTwo" placeholder="请输入有无变动2" />
        </el-form-item>
        <el-form-item label="有无变动3" prop="moveThree">
          <el-input v-model="form.moveThree" placeholder="请输入有无变动3" />
        </el-form-item>
        <el-form-item label="目前实习单位/待业地址" prop="currentAddress">
          <el-input v-model="form.currentAddress" placeholder="请输入目前实习单位/待业地址" />
        </el-form-item>
        <el-form-item label="岗位" prop="jobs">
          <el-input v-model="form.jobs" placeholder="请输入岗位" />
        </el-form-item>
        <el-form-item label="当前薪资" prop="currentSalary">
          <el-input v-model="form.currentSalary" placeholder="请输入当前薪资" />
        </el-form-item>
        <el-form-item label="是否签订协议" prop="employmentAgreement">
          <el-radio-group v-model="form.employmentAgreement">
            <el-radio label="1">是</el-radio>
            <el-radio label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="学员状态(未就业/在职/已离职/已跳槽)" prop="studentStatus">
          <el-radio-group v-model="form.studentStatus">
            <el-radio label="未就业">未就业</el-radio>
            <el-radio label="在职">在职</el-radio>
            <el-radio label="已离职">已离职</el-radio>
            <el-radio label="已跳槽">已跳槽</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="推荐方式" prop="recommendWays">
          <el-input v-model="form.recommendWays" placeholder="请输入推荐方式" />
        </el-form-item>
        <el-form-item label="推荐老师" prop="recommendTeacher">
          <el-input v-model="form.recommendTeacher" placeholder="请输入推荐老师" />
        </el-form-item>
        <el-form-item label="是否对口" prop="counterpart">
          <el-radio-group v-model="form.counterpart">
            <el-radio label="1">是</el-radio>
            <el-radio label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否核心对口" prop="coreCounterpart">
          <el-radio-group v-model="form.coreCounterpart">
            <el-radio label="1">是</el-radio>
            <el-radio label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="回访记录" prop="returnVisit">
          <el-input v-model="form.returnVisit" placeholder="请输入回访记录" />
        </el-form-item>
        <el-form-item label="就业照片" prop="jobPicture">
          <el-input v-model="form.jobPicture" placeholder="请输入就业照片" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { addEmploymentlist } from '@/api/employment/employmentlist'
export default {
  name: 'EntryEmployment',
  data() {
    return {
    // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        studentId: [
          { required: true, message: '学生id不能为空', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        firstInternshipDate: [
          { required: true, message: '初次报到时间不能为空', trigger: 'blur' }
        ],
        firstInternshipCompany: [
          { required: true, message: '初次报到单位不能为空', trigger: 'blur' }
        ],
        studentStatus: [
          { required: true, message: '学员状态(未就业/在职/已离职/已跳槽)不能为空', trigger: 'blur' }
        ],
        currentSalary: [
          { required: true, message: '当前薪资不能为空', trigger: 'blur' }
        ],
        employmentAgreement: [
          { required: true, message: '是否签订协议不能为空', trigger: 'blur' }
        ],
        recommendWays: [
          { required: true, message: '推荐方式不能为空', trigger: 'blur' }
        ],
        recommendTeacher: [
          { required: true, message: '推荐老师不能为空', trigger: 'blur' }
        ],
        counterpart: [
          { required: true, message: '是否对口不能为空', trigger: 'blur' }
        ],
        coreCounterpart: [
          { required: true, message: '是否核心对口不能为空', trigger: 'blur' }
        ],
        returnVisit: [
          { required: true, message: '回访记录不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.reset()
    this.open = true
    this.title = '添加就业列表'
  },
  methods: {
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加就业列表'
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        employmentId: null,
        studentId: null,
        name: null,
        firstInternshipDate: null,
        firstInternshipCompany: null,
        moveOne: null,
        moveTwo: null,
        moveThree: null,
        studentStatus: '0',
        currentAddress: null,
        jobs: null,
        currentSalary: null,
        employmentAgreement: null,
        recommendWays: null,
        recommendTeacher: null,
        counterpart: null,
        coreCounterpart: null,
        returnVisit: null,
        jobPicture: null
      }
      this.resetForm('form')
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.employmentId != null) {
            updateEmploymentlist(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addEmploymentlist(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    }

  }
}
</script>

<style>

</style>
